//
//  ArticleCell.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/11.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class ArticleCell: UITableViewCell {
    
    fileprivate let titleLabel = UILabel() //标题
    fileprivate let contextLabel = UILabel() //内容
    fileprivate let timeLabel = UILabel() //时间
    
    var model : ArticleModel! {
        
        didSet{
            updateData()
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        titleLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.contentView.addSubview(titleLabel)
        
        contextLabel.numberOfLines = 2
        contextLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        contextLabel.textColor = UIColor.gray
        self.contentView.addSubview(contextLabel)
        
        timeLabel.textAlignment = .right
        timeLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        self.contentView.addSubview(timeLabel)
        
        let grayView = UIView()
        grayView.backgroundColor = UIColor.lineColor()
        self.contentView.addSubview(grayView)
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 8))
            make.right.equalToSuperview().offset(RATIO(maxNum: -8))
            make.top.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
        
        contextLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel)
            make.right.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom)
            make.height.equalTo(RATIO_H(maxNum: 40))
        }
        
        timeLabel.snp.makeConstraints { (make) in
            make.right.equalTo(contextLabel)
            make.left.equalTo(contextLabel)
            make.top.equalTo(contextLabel.snp.bottom)
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
        
        grayView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    //MARK: 更新数据
    fileprivate func updateData() {
        
        titleLabel.text = model.posts_title
        contextLabel.text = model.posts_excerpt
        timeLabel.text = model.update_time?.getDate()
    }

}
